//
//  TopView.m
//  BeautifulLockerRoom
//
//  Created by mac on 16/7/29.
//  Copyright © 2016年 Winny. All rights reserved.
//

#import "TopView.h"

@implementation TopView

-(MidView *)mid
{
    if (!_mid) {
        _mid = [[MidView alloc]init];        
    }
    return _mid;
}
-(SmallScrollView *)smallSV
{
    if (!_smallSV)
    {
        _smallSV = [[SmallScrollView alloc]init];
        
    }
    return _smallSV;
}
-(UIPageControl *)pageControl
{
    if (!_pageControl)
    {
        _pageControl=[[UIPageControl alloc]init];
        _pageControl.bounds=CGRectMake(0, 0, 130, 30);
        _pageControl.center=CGPointMake(_smallSV.center.x, _smallSV.center.y + 50);
        _pageControl.numberOfPages=4;
        _pageControl.currentPage=0;
        
        _pageControl.currentPageIndicatorTintColor = [UIColor redColor];
        _pageControl.pageIndicatorTintColor = [UIColor whiteColor];
        [_pageControl addTarget:self action:@selector(imageOffset) forControlEvents:UIControlEventValueChanged];
        _timer=[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(pageMove) userInfo:nil repeats:YES];
    }
    return _pageControl;
}
-(instancetype)init
{
    self = [super init];
    if (self)
    {
        [self addSubview:self.smallSV];
        [self addSubview:self.pageControl];
        [self addSubview:self.mid];
    }
    return self;
}
-(void)pageMove
{
    static int a=1;
    if (_pageControl.currentPage==0)
    {
        a=1;
        
    }
    if (_pageControl.currentPage==3) {
        a=-1;
        
    }
    _pageControl.currentPage = _pageControl.currentPage+a;
    NSInteger x = _pageControl.currentPage;
    NSInteger y;
    y = x * WINDOWWIDTH;
    [_smallSV setContentOffset:CGPointMake(y, 0) animated:YES];
}


/*
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView;
 {
 offset_x = self.contentOffset.x;
 static UIButton * button = nil;
 if (!button)
 {
 button = [UIButton buttonWithType:UIButtonTypeCustom];
 button.frame = CGRectMake(-54654, -6546546, 30, 30);
 [button setBackgroundImage:[UIImage imageNamed:@"go_top_btn"] forState:UIControlStateNormal];
 [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
 
 }
 
 if (self.contentOffset.y >= 260)
 {
 button.frame = CGRectMake(WINDOWWIDTH - 45, WINDOWHEIGHT - 109 + 15 , 30, 30);
 }
 else
 {
 button.frame = CGRectMake(-54654, -6546546, 30, 30);
 }
 [self.superview addSubview:button];
 }
 */
-(void)buttonClick
{
    //self.contentOffset = CGPointMake(offset_x, 0);
}
-(void)imageOffset
{
    [UIView animateWithDuration:0.25 animations:^{
        _smallSV.contentOffset = CGPointMake(_pageControl.currentPage * WINDOWWIDTH, 0);
    }];
    
}


@end
